import './WJHAlarmInformation.scss'
import dayjs from 'dayjs'
import { TextList001 } from '../Common/TextList'
import { useMount, useRequest } from 'ahooks'
import { Http } from '../../../../Common/Api'
import { useState } from 'react'

const Top = [
    { uuid: 1, label: '报警时间', value: 'A01', flex: 1 },
    { uuid: 2, label: '设备名称', value: 'A02', flex: 2 },
    { uuid: 3, label: '信息内容', value: 'A03', flex: 3 },
]

export const WJHAlarmInformationA01 = () => {
    const [Data, setData] = useState([])

    const { runAsync } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            setData(
                res.data.map(({ warningTime, deviceName, warningInfo }) => ({
                    A01: dayjs(warningTime).format('HH:mm:ss'),
                    A02: deviceName,
                    A03: warningInfo,
                })),
            )
        },
    })

    useMount(() => {
        runAsync({ url: 'getWJHwarning' })
    })

    return (
        <div className="WJHAlarmInformationA01">
            <TextList001 Top={Top} data={Data} />
        </div>
    )
}
